package hn.cch.agent;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;

public class MyClassFileTransformer implements ClassFileTransformer {
    @Override
    public byte[] transform(ClassLoader loader, String className,
                            Class<?> classBeingRedefined,
                            ProtectionDomain protectionDomain,
                            byte[] classfileBuffer) throws IllegalClassFormatException {
        System.out.println("transform:" + className);
        // 非自有类, 直接返回
        if (!className.startsWith("hn.cch")) {
            return classfileBuffer;
        }
        // 为null，表示由BootstrapClassLoader加载的，不能重写
        if (loader == null) {
            return classfileBuffer;
        }
        // code
        return classfileBuffer;
    }
}
